<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%@page import="org.springframework.util.CollectionUtils"%>
<%@page import="java.util.Collection"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ include file="../common/common_include.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	List<TblCheckLeave> list = (List<TblCheckLeave>)request.getAttribute("list");
	LeaveForm form = (LeaveForm)request.getAttribute("command");
	UserInfo user = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	String username = user.getName();
	String userid = user.getUsername();
	String siteid = user.getSiteId();
	String sitename = user.getSiteName();
	String deptid = user.getDeptId();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
	String year_moth = sdf.format(new Date());
%>
<div class="userListWrap">
    <form id="userListForm">
        <div class="form-item" style="width:180px;">
    		<label for="year_month">请假年月:</label>
    		<input class="easyui-validatebox"  style="width:80px;height: 22px;" type="text" id="year_month" value="<%=StringUtils.isNotBlank(form.getYear_month())?form.getYear_month():"" %>" name="year_month" onClick="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM',maxDate:'%y-%M'})">
        </div>
        <div class="form-item" style="width:180px;">
        	<label for="siteid">所属公司：</label>
			<select  id="siteList" class="easyui-combobox" style="width:100px;" name="siteid" ></select>
		</div>
		<div class="form-item" style="width:180px;">
			<label for="deptid">部门：</label>
			<select id="deptList" class="easyui-combobox" style="width:100px;" name="deptid" ></select>
		</div>
        <div class="form-item" style="width:180px;">
    		<label for="userid">员工编号:</label>
    		<input  class="easyui-validatebox" style="width:100px;height: 22px;"  type="text" id="userid" value="<%=StringUtils.isNotBlank(form.getUserid())?form.getUserid():"" %>" name="userid" >
        </div>     	
        <div class="form-item" >
    		<a href="javascript:XF.Check.personLeaveListSearch()" class="input-btn-microsoft input-btn-microsoft-24">搜索</a>
        </div>        
    </form>
    <table id="LeaveUserListTable" class="easyui-datagrid" title="<%=StringUtils.isNotBlank(form.getYear_month())?form.getYear_month():"" %>请假记录" >
        <thead>
    		<tr>
    			<th data-options="field:'userid',width:80">员工编号</th>
    			<th data-options="field:'username',width:70">员工姓名</th>
				<th data-options="field:'deptname',width:70">部门</th>
    			<th data-options="field:'startdate',width:110">请假开始日期</th>
    			<th data-options="field:'enddate',width:110">请假结束日期</th>					
				<th data-options="field:'type',width:60">请假类型</th>
				<th data-options="field:'reason',width:100" >请假原因</th>
				<th data-options="field:'addtim',width:110" >操作时间</th>
				<th data-options="field:'personflag',width:120">操作</th>
				<th data-options="field:'personuser',width:80">人事部审核人</th>
				<th data-options="field:'personremark',width:100">人事部原因</th>
				<th data-options="field:'deptflag',width:80">部门审核状态</th>
				<th data-options="field:'deptuser',width:70">部门审核人</th>
				<th data-options="field:'deptremark',width:100">部门审核原因</th>
				<th data-options="field:'flag',width:80" >员工状态</th>
				<th data-options="field:'remark',width:240" >员工销毁原因</th>
      		</tr>
        </thead>
        <tbody>
        	<%
        		if(list!=null && list.size() > 0){
        			for(TblCheckLeave leave:list){
        				%>
       					 <tr s="<%=leave.getId()+"" %>">
       					 	<td><i s="<%=leave.getId()+"" %>"></i><%=(null!=leave.getUserid())?leave.getUserid()+"":"" %></td>
       					 	<td><%=(null!=leave.getUsername())?leave.getUsername()+"":"" %></td>					 	      					 	
       					 	<td><%=(null!=leave.getDeptname())?leave.getDeptname()+"":"" %></td>
       					 	<td><%=leave.getStartdate()!=null?DateFormatUtils.format(leave.getStartdate(), "yyyy-MM-dd HH:mm"):"" %></td>
							<td><%=leave.getEnddate()!=null?DateFormatUtils.format(leave.getEnddate(), "yyyy-MM-dd HH:mm"):"" %></td>
       					 	<td><%=null!=leave.getType()?leave.getType()+"":"" %></td>
       					 	<td><%=(null!=leave.getReason())?leave.getReason()+"":"" %></td>
       					 	<td><%=null!=leave.getAddtime()?DateFormatUtils.format(leave.getAddtime(), "yyyy-MM-dd HH:mm"):"" %></td>
       					 	<td><div id='opts<%=leave.getId() %>' class="innerBtnWrap">
       					 			<%if(leave.getPersonflag()!=null && leave.getDeptflag() !=null){
       					 				if(leave.getPersonflag().equals(0)){%>
	       					 				<a class="inLink" id="e<%=leave.getId() %>" href="javascript:XF.Check.editPersonLeave(<%=leave.getId() %>)">修改</a>
											<a class="inLink" id="d<%=leave.getId() %>" href="javascript:XF.Check.deleteLeave('<%=leave.getId() %>')">删除</a>
											<a class="inLink" id="p<%=leave.getId() %>" href="javascript:XF.Check.auditPersonLeave(<%=leave.getId() %>,'2','d')">审核</a>
										<%}else if(leave.getDeptflag().equals(3) && !leave.getPersonflag().equals(3)){%>
											<a class="inLink" id="d<%=leave.getId()+""%>" href="javascript:XF.Check.personDestroyLeave(<%=leave.getId() %>)">同意销毁</a>
										<%}else if(leave.getDeptflag().equals(2) && !leave.getPersonflag().equals(2) && !leave.getPersonflag().equals(1) && !leave.getPersonflag().equals(3) ){%>
											<a class="inLink" id="a<%=leave.getId() %>" href="javascript:XF.Check.auditPersonLeave(<%=leave.getId() %>,'2','p')">审核通过</a>
											<a class="inLink" id="n<%=leave.getId() %>" href="javascript:XF.Check.noPersonLeave(<%=leave.getId() %>)">不通过</a>
										<%}else if(leave.getPersonflag().equals(3)){%>
										<span id='span<%=leave.getId() %>' class="inLink"><font color='#FF0000'>已同意销毁</font></span>	
										<%}else if(leave.getPersonflag().equals(1)){%>
										<span id='span<%=leave.getId() %>' class="inLink"><font color='#FF0000'>审核不通过</font></span>
										<%}else if(leave.getPersonflag().equals(2) && leave.getFlag().equals(0)){%>
										<span id='span<%=leave.getId() %>' class="inLink">已审核通过</span>
										<a class="inLink" id="cdp<%=leave.getId() %>" href="javascript:XF.Check.auditPersonLeave(<%=leave.getId() %>,'4','cdp')">反审核</a>
										<%}else if(leave.getPersonflag().equals(2) && leave.getFlag().equals(2)){%>
										<span  id='span<%=leave.getId() %>'class="inLink">已审核通过</span>
										<a class="inLink" id="cp<%=leave.getId() %>" href="javascript:XF.Check.auditPersonLeave(<%=leave.getId() %>,'0','cp')">反审核</a>	
										<%}
       					 			}
									%>																		
								</div>
       					 	</td>
       					 	<td><%=(null!=leave.getPersonuser())?leave.getPersonuser()+"":"" %></td>
       					 	<td><%=(null!=leave.getPersonremark())?leave.getPersonremark()+"":"" %></td>
       					 	<td><%if(leave.getDeptflag() !=null && leave.getDeptflag().equals(2)){ %>
       					 			<span>部门已审核</span>
       					 		<%}else if(leave.getDeptflag() !=null && leave.getDeptflag().equals(3)){%>
       					 			<span><font color='#FF0000'>部门已销毁</font></span>
       					 		<%}%>
							</td>       					 	
       					 	<td><%=(null!=leave.getDeptuser())?leave.getDeptuser()+"":"" %></td>
       					 	<td><%=leave.getDeptremark()!=null?leave.getDeptremark()+"":"" %></td>
       					 	<td><%if(leave.getFlag() !=null && leave.getFlag().equals(3)){%>
       					 			<span><font color='#FF0000'>已申请销毁</font></span>
       					 		<%}%>
       					 	</td>       					 	
       					 	<td><%=(null!=leave.getRemark())?leave.getRemark()+"":"" %></td>
			    		</tr>
        				<%
        			}
        		}
        	%>
    	</tbody>
    </table>
    <div class="pagination paginationFixWidth">
		<monggoTag:pagination 
		href="leave_person_search"
		pageSize="<%=form.getPageSize()%>" 
		totalRecord="<%=form.getTotalRecord() %>" 
		currentPage="<%=form.getPageNum() %>">
		</monggoTag:pagination> 
	</div>	
</div>
<script>
$('#LeaveUserListTable').datagrid();
var sid = '<%=form.getSiteid() %>';
$('#siteList').combobox({
	url:global.contextPath + '/company/siteList',
	valueField:'siteid',
	textField:'sitename',
	panelHeight: 'auto',
	editable:false,
	onSelect:function(record){
		 $('#deptList').combobox('clear'); //清除原来的数据  
        var url = global.contextPath + '/company/datagridDepts?siteid=' + record.siteid;  
        $('#deptList').combobox('reload', url);//联动下拉列表重载 
       },
});
$('#deptList').combobox({
	valueField:'deptid',
	textField:'deptname',								
	url:global.contextPath + '/company/datagridDepts?siteid=' + sid,
	panelHeight: 'auto'
});
$('#siteList').combobox('setValue', '<%=form.getSiteid() %>');
</script>